﻿#region File Info Header
/*________________________________________________________________________________________

  Copyright (C) 2011 Jason Zhang, eagleboost@msn.com

  * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
  * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

________________________________________________________________________________________*/
#endregion File Info Header

namespace EagleBoost.Wpf.Presentation.Extensions
{
  using System.Linq;
  using System.Windows;
  using System.Windows.Media;

  /// <summary>
  /// Extension methods for Color
  /// </summary>
  public static class ColorExtension
  {
    /// <summary>
    /// Convert Color to string
    /// </summary>
    /// <param name="color"></param>
    /// <returns></returns>
    public static string ColorString(this Color color)
    {
      foreach (var property in from property in typeof (SystemColors).GetProperties()
                               where property.PropertyType == typeof (Color)
                               let knowColor = (Color) property.GetValue(null, null)
                               where color == knowColor
                               select property)
      {
        return string.Format("{0}:({1},{2},{3})", property.Name, color.R, color.G, color.B);
      }

      foreach (var property in from property in typeof (Colors).GetProperties()
                               let knowColor = (Color) property.GetValue(null, null)
                               where color == knowColor
                               select property)
      {
        return string.Format("{0}:({1},{2},{3})", property.Name, color.R, color.G, color.B);
      }

      return string.Format("{0}:({1},{2},{3})", color, color.R, color.G, color.B);
    }
  }
}
